
Page({
    data: {
         userInfo:{}

        
    },
    onLoad:function(opt){
        var userInfo= wx.getStorageSync('userInfo');
        this.setData({
            userInfo:userInfo
        })
    },
    onShow:function(){
     
    },
    onMyEvent:function(e){
        console.log(e.detail)
        
    },chooseImage:function () {
      var _self=this;
      wx.chooseImage({
        success (res) {
          const tempFilePaths = res.tempFilePaths
          console.log(tempFilePaths[0])
          var imgUrl=tempFilePaths[0]
        
          console.log('##################')
          wx.uploadFile({
             url:getApp().globalData.baseUrl+'/wx/img/url', //仅为示例，非真实的接口地址
            //url:getApp().globalData.baseUrl+'/imagesnode/uploadImg',
            filePath: tempFilePaths[0],
            header: {
              'content-type':'multipart/form-data',
              'openid':_self.data.userInfo.openid 
            },
            name: 'filePath',
            formData: {
              openid:_self.data.userInfo.openid 
            },
            success (res){
              var data = JSON.parse(res.data);
              console.log(data.obj)
                var userInfo=_self.data.userInfo;
                userInfo.avatarUrl=data.obj;

                _self.setData({
                  userInfo:userInfo
                })
              //do something
            }
          })
        }
      })
    },

     //输入型号
    textModel:function (e) {
       var json=this.data.userInfo;
       json.nickName=e.detail.value;
       this.setData({
        userInfo:json
      })
    },
    sendSheQu:function () {
     if(this.data.userInfo.nickName==''){
        wx.showToast({
          title: '请填写完整信息',
          icon:'none',
          duration: 2000
        })
       // return
     }
    var _self=this;
     wx.request({
            url:getApp().globalData.baseUrl+'/wx/user/update',
            method:"post",
            header:{
               'openid':this.data.userInfo.openid, //公用请求头
               'content-type': 'application/json'
            },
            data:this.data.userInfo,
            success: function(res) {
              if (res.data.code==200) {

                wx.navigateBack({
                  delta: 1
                })
              }
            console.log(res)  
            
         }
       })
    }
});